import { CreateQueryParams } from '@dataui/crud-request';
import { FindManyOptionsReq } from '@nest-crud/request-typeorm/find-options';
import { deepSetFieldsAndJoin } from './trans-item/fields-and-join';
import { deepSetConditions } from './trans-item/search';
import { deepSetSort } from './trans-item/sort';
// [ ]是否分页
export function transFind(findOptions: FindManyOptionsReq): CreateQueryParams {
  const res: CreateQueryParams = { sort: [] };
  //=== set Fields and Join
  const fieldsAndJoin = deepSetFieldsAndJoin(findOptions);
  res.fields = fieldsAndJoin.fields;
  res.join = fieldsAndJoin.join;
  //=== setSort
  res.sort = deepSetSort(findOptions.order);
  //===  search
  res.search = deepSetConditions(findOptions);

  res.limit = findOptions.take;
  res.offset = findOptions.skip;
  if (findOptions.withDeleted) res.includeDeleted = 1;
  if (findOptions.cache === false) res.resetCache = true;
  console.log('transFind', res);
  return res;
}
